/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

//package sim;
import java.io.*;

/**
 *
 * @author Vu Duc Tiep
 */
public class gnuPlotCreater {
    static public void setContents(File aFile, String aContents)
                                 throws FileNotFoundException, IOException {
        if (aFile == null) {
          throw new IllegalArgumentException("File should not be null.");
        }
        if (!aFile.exists()) {
            aFile.createNewFile();
            //throw new FileNotFoundException ("File does not exist: " + aFile);
        }
        if (!aFile.isFile()) {
          throw new IllegalArgumentException("Should not be a directory: " + aFile);
        }
        if (!aFile.canWrite()) {
          throw new IllegalArgumentException("File cannot be written: " + aFile);
        }

        //use buffering
        Writer output = new BufferedWriter(new FileWriter(aFile,true));
        try {
          //FileWriter always assumes default encoding is OK!
          output.write( aContents );
        }
        finally {
          output.close();
        }
    }
    public static void main(String[]args) throws IOException {    
   
        File waveFile= new File("wave.dat");
        int count=1;
        for(int i=0;i<args.length;i++)
        {
            if(count==3)
            {    
                setContents(waveFile,args[i]+System.getProperty("line.separator"));
                count=1;
            }
            else{
                setContents(waveFile,args[i]+" " );count++;
            }
            
        }
        //System.out.println("New file contents: " + getContents(testFile));
    }
}
